package java_thinking.unit_5._5_1;// initialization/ConstructorTest.java
// ITJ4 Chapter Initialization, Exercise6 1, p158
// Create a class containing an unitialized String reference. Demonstrate that // this reference is initialized by Java to null.

class Tester {
	String str1 = "hello";
	String str2 = null;
	String str3 = str2;
	String str4 = str1+str2+str3;
	public Tester(String str2){
		System.out.println("str4:"+str4);
		System.out.println("str1+str2+str3 :"+str1+this.str2+str3);
		this.str2 = str2;
		System.out.println("str4:"+str4);
		System.out.println("str1+str2+str3 :"+str1+this.str2+str3);

	}
}

/**
 * @author asd730520@live.com
 */
public class ConstructorTest {
	public static void main(String[] args) {
		Tester t = new Tester("word");
		System.out.println("str1: "+t.str1);

		System.out.println("str2: "+t.str2);
		System.out.println("str3: "+t.str3);
		System.out.println("str4: "+t.str4);
		/*
		Tester初始化时str1~3分别被初始化了一次，结果如下
		str1: hello
		str2: null
		str3: null
		当另一个通过构造器初始化Tester str2又被赋值了一次
		str1: hello
		str2: word
		str3: null
		而str4都是hello null null因为定义时他指向的地址内容是3个str字符串相加内容，已经不是地址引用了，其他3个str再变化都没用了

		* */
	}
}